﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.DeviceManage;
using ProduceBasicData.Api.DTO.DeviceDto;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.DeviceManage
{
    /// <summary>
    /// 设备类型控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeviceTypeController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public DeviceTypeController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 创建设备类型
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateDeviceType(CreateDeviceTypeCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取设备类型列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<DeviceTypeDto>> GetDeviceTypeList([FromQuery] GetDeviceTypeCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新设备类型
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateDeviceType(UpdateDeviceTypeCommand command)
        {
            return await _mediator.Send(command);   
        }
        /// <summary>
        /// 删除设备类型
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteDeviceType(DeleteDeviceTypeCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 设备类型批量删除接口
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeDeviceType(DeleteRangeDeviceTypeCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
